package com.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @description: WSMessageService
 * @author: Administrator
 * @create: 2018-08-17 10:48
 **/
@Service("webSocketMessageService")
public class WSMessageService {
    private Logger logger = LoggerFactory.getLogger(WSMessageService.class);
    //声明websocket连接类
    private WebSocketChat webSocketChat = new WebSocketChat();

    /**
     * @Title: sendToAllTerminal
     * @Description: 调用websocket类给用户下的所有终端发送消息
     * @param @param userId 用户id
     * @param @param message 消息
     * @param @return 发送成功返回true，否则返回false
     */
    public Boolean sendToAllTerminal(String userId,String message){
        logger.info("向用户{}的消息：{}",userId,message);
        if(webSocketChat.sendMessageToUser(userId,message)){
            return true;
        }else{
            return false;
        }
    }

    /*** 
    * @Description:  调用websocket类给所有用户下的所有终端发送消息
    * @param message 
    * @return: java.lang.Boolean 
    * @Author:Administrator
    * @Date: 2018/8/17 
    */ 
    public Boolean sendmsgToAll(String message){
        if(webSocketChat.sendMessage(message)){
            return true;
        }else{
            return false;
        }
    }
}
